//
//  GMIndicatorView.m
//  golfMaster
//
//  Created by suixuexiang on 21/7/14.
//  Copyright (c) 2014 Master. All rights reserved.
//

#import "GMIndicatorView.h"

#define Key_RotationAnimation   @"transform.rotation.z"


static const float ROTATE_DURATION = 1;

@interface GMIndicatorView()

@property (nonatomic, strong) UIImageView *imageView;

@end


@implementation GMIndicatorView

- (void)awakeFromNib
{
    self.hidden = YES;
    self.imageView = [[UIImageView alloc] initWithImage:PCImage(@"CustomIndicator")];
    [self addSubview:self.imageView];
    self.frame = self.imageView.bounds;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.hidden = YES;
        self.imageView = [[UIImageView alloc] initWithImage:PCImage(@"CustomIndicator")];
        [self addSubview:self.imageView];
        self.frame = self.imageView.bounds;
    }
    return self;
}

- (void)startAnimating
{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:Key_RotationAnimation];
    animation.duration = ROTATE_DURATION;
    animation.RepeatCount = HUGE_VALF;
    animation.cumulative = NO;
    animation.fromValue = @(0);
    animation.toValue = @(M_PI * 2.0);
    [self.imageView.layer addAnimation:animation forKey:Key_RotationAnimation];
    
    self.hidden = NO;
}

- (void)stopAnimating
{
    [self.imageView.layer removeAnimationForKey:Key_RotationAnimation];
    self.hidden = YES;
}

- (BOOL)isAnimating
{
    return !self.hidden;
}

@end
